package com.technology.io;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import com.technology.other.Human;

public class SerializationUsing {

	public static void main(String[] args) {
		Human ivan = new Human();
		ivan.setLastName("Ivanov");
		ivan.setWeught(90);
		ivan.setHeight(200);
		
		try {
			ObjectOutputStream oos = 
					new ObjectOutputStream(new FileOutputStream("src/com/technology/io/human.ser"));
			oos.writeObject(ivan);
			oos.flush();
			oos.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		try {
			ObjectInputStream ois = new ObjectInputStream(new FileInputStream("src/com/technology/io/human.ser"));
			Object anotherHuman = ois.readObject();
			if (anotherHuman instanceof Human){
				Human man = (Human) anotherHuman;
				System.out.println("Name: " + man.getLastName());
				System.out.println("Heigth: " +man.getHeight());
				System.out.println("Weight: " +man.getWeught());
			}
			
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
